package com.example.seckill;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SeckillApplication {

    public static void main(String[] args) {
        initFlowRules();
        SpringApplication.run(SeckillApplication.class, args);
    }

    private

    static void
    initFlowRules
            () {

        List
                <
                        FlowRule
                        >
                rules
                =

                new

                        ArrayList
                                <>();


        FlowRule
                rule
                =

                new

                        FlowRule
                        ();
        rule
                .
                        setResource
                                (
                                        "sentinelLimiter"
                                );
        rule
                .
                        setGrade
                                (
                                        RuleConstant
                                                .
                                                FLOW_GRADE_QPS
                                );
        rule
                .
                        setCount
                                (
                                        10
                                );
        rules
                .
                        add
                                (
                                        rule
                                );


        FlowRuleManager
                .
                        loadRules
                                (
                                        rules
                                );

    }
}
